package com.leetone.microserver.util;

import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ServiceInfoUtil implements ApplicationListener<EmbeddedServletContainerInitializedEvent> {
    /**
     * @description 【声明event对象，该对象用于获取运行服务器的本地端口】
     * @param null
     * @return
     * @exception
     * @author leetone 【leetone123@163.com】
     * @date 2019/3/16 16:05
     */
    private static EmbeddedServletContainerInitializedEvent event;

    @Override
    public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) {
        ServiceInfoUtil.event = event;
    }

    /*
     * @description 【获取端口号】
     * @param null
     * @return
     * @exception
     * @author leetone 【leetone123@163.com】
     * @date 2019/3/16 16:07
     */
    public static int getPort() {
        int port = event.getEmbeddedServletContainer().getPort();
        return port;
    }
}
